# NOT RUN {
mysequence <- s2c("agtctggggggccccttttaagtagatagatagctagtcgta")
GC(mysequence) # 0.4761905
GC1(mysequence) # 0.6428571
GC2(mysequence) # 0.3571429
GC3(mysequence) # 0.4285714
#
# With upper-case characters:
#
myUCsequence <- s2c("GGGGGGGGGA")
GC(myUCsequence) # 0.9
#
# With ambiguous bases:
#
GC(s2c("acgt")) # 0.5
GC(s2c("acgtssss")) # 0.5
GC(s2c("acgtssss"), exact = TRUE) # 0.75
#
# Missing data:
#
stopifnot(is.na(GC(s2c("NNNN"))))
stopifnot(is.na(GC(s2c("NNNN"), exact = TRUE)))
stopifnot(is.na(GC(s2c("WWSS"))))
stopifnot(GC(s2c("WWSS"), exact = TRUE) == 0.5)
#
# Coding sequences tests:
#
cdstest <- s2c("ATGATG")
stopifnot(GC3(cdstest) == 1)
stopifnot(GC2(cdstest) == 0)
stopifnot(GC1(cdstest) == 0)
#
# How to reproduce the results obtained with the C program codonW
# version 1.4.4 writen by John Peden. We use here the "input.dat"
# test file from codonW (there are no ambiguous base in these
# sequences).
#
inputdatfile <- system.file("sequences/input.dat", package = "seqinr")
input <- read.fasta(file = inputdatfile) # read the FASTA file
inputoutfile <- system.file("sequences/input.out", package = "seqinr")
input.res <- read.table(inputoutfile, header = TRUE) # read codonW result file
#
# remove stop codon before computing G+C content (as in codonW)
#
GC.codonW <- function(dnaseq, ...){
GC(dnaseq[seq_len(length(dnaseq) - 3)], ...)
}
input.gc <- sapply(input, GC.codonW, forceToLower = FALSE)
max(abs(input.gc - input.res$GC)) # 0.0004946237
plot(x = input.gc, y = input.res$GC, las = 1,
xlab = "Results with GC()", ylab = "Results from codonW",
main = "Comparison of G+C content results")
abline(c(0, 1), col = "red")
legend("topleft", inset = 0.01, legend = "y = x", lty = 1, col = "red")
# }
# NOT RUN {
# Too long for routine check
# This is a benchmark to compare the effect of various parameter
# setting on computation time
n <- 10
from <-10^4
to <- 10^5
size <- seq(from = from, to = to, length = n)
res <- data.frame(matrix(NA, nrow = n, ncol = 5))
colnames(res) <- c("size", "FF", "FT", "TF", "TT")
res[, "size"] <- size
for(i in seq_len(n)){
myseq <- sample(x = s2c("acgtws"), size = size[i], replace = TRUE)
res[i, "FF"] <- system.time(GC(myseq, forceToLower = FALSE, exact = FALSE))[3]
res[i, "FT"] <- system.time(GC(myseq, forceToLower = FALSE, exact = TRUE))[3]
res[i, "TF"] <- system.time(GC(myseq, forceToLower = TRUE, exact = FALSE))[3]
res[i, "TT"] <- system.time(GC(myseq, forceToLower = TRUE, exact = TRUE))[3]
}
par(oma = c(0,0,2.5,0), mar = c(4,5,0,2) + 0.1, mfrow = c(2, 1))
plot(res$size, res$TT, las = 1,
xlab = "Sequence size [bp]",
ylim = c(0, max(res$TT)), xlim = c(0, max(res$size)), ylab = "")
title(ylab = "Observed time [s]", line = 4)
abline(lm(res$TT~res$size))
points(res$size, res$FT, col = "red")
abline(lm(res$FT~res$size), col = "red", lty = 3)
points(res$size, res$TF, pch = 2)
abline(lm(res$TF~res$size))
points(res$size, res$FF, pch = 2, col = "red")
abline(lm(res$FF~res$size), lty = 3, col = "red")
legend("topleft", inset = 0.01,
legend = c("forceToLower = TRUE", "forceToLower = FALSE"),
col = c("black", "red"), lty = c(1,3))
legend("bottomright", inset = 0.01, legend = c("exact = TRUE", "exact = FALSE"),
pch = c(1,2))
mincpu <- lm(res$FF~res$size)$coef[2]
barplot(
c(lm(res$FF~res$size)$coef[2]/mincpu,
lm(res$TF~res$size)$coef[2]/mincpu,
lm(res$FT~res$size)$coef[2]/mincpu,
lm(res$TT~res$size)$coef[2]/mincpu),
horiz = TRUE, xlab = "Increase of CPU time",
col = c("red", "black", "red", "black"),
names.arg = c("(F,F)", "(T,F)", "(F,T)", "(T,T)"), las = 1)
title(ylab = "forceToLower,exact", line = 4)
mtext("CPU time as function of options", outer = TRUE, line = 1, cex = 1.5)
# }
Run the code above in your browser using DataLab